home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / Macintosh Sample Code / SC.014.CPlusTESample / List.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-18  |  2.2 KB  |  101 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------------------
  2.  
  3.     Program:    CPlusTESample 2.0
  4.     File:        List.h
  5.  
  6.     by Andrew Shebanow
  7.     of Apple Macintosh Developer Technical Support
  8.  
  9.     Copyright © 1989-1990 Apple Computer, Inc.
  10.     All rights reserved.
  11.  
  12. ------------------------------------------------------------------------------------------*/
  13.  
  14. #ifndef __LIST__
  15. #define __LIST__
  16.  
  17. // HandleObjectHandle is an Handle full of HandleObject*,
  18. // which we use as an array
  19. // We do two typedefs here to make that a
  20. // bit easier to read, since:
  21. //        typedef HandleObject*** HandleObjectHandle;
  22. // is just too wierd.
  23. typedef HandleObject* HandleObjectRef;
  24. typedef HandleObjectRef** HandleObjectHandle;
  25.  
  26. class TList : public HandleObject {
  27. public:
  28.     TList();
  29.  
  30.     virtual void            InsertFirst(HandleObject* obj);
  31.     virtual void            InsertLast(HandleObject* obj);
  32.  
  33.     virtual void            MoveToFront(HandleObject* obj);
  34.     virtual void            MoveToBack(HandleObject* obj);
  35.     virtual void            MoveFront(HandleObject* obj);
  36.     virtual void            MoveBack(HandleObject* obj);
  37.  
  38.     virtual void            Remove(HandleObject* obj);
  39.     virtual void            RemoveAll();
  40.     virtual void            Delete(HandleObject* obj);
  41.     virtual void            DeleteAll();
  42.  
  43.     virtual short            Count() const;
  44.  
  45. protected:
  46.     virtual HandleObject*    At(short idx) const;
  47.     virtual short            FindIdx(HandleObject* obj);
  48.  
  49.     short                    fNumObjs;        // the number of elements in the list
  50.  
  51. private:
  52.     friend class TListIterator;
  53.  
  54.     HandleObjectHandle    fObjects;
  55. };
  56.  
  57. // Our inline methods - we do these so often, and they are so small,
  58. // that we make them inlines
  59.  
  60. inline short TList::Count() const
  61. {
  62.     return fNumObjs;
  63. }
  64.  
  65. class TListIterator : public HandleObject {
  66. public:
  67.                             TListIterator(const TList* ls);
  68.     virtual    HandleObject*    Next();
  69.     virtual    HandleObject*    Prev();
  70.     virtual    HandleObject*    First();
  71.     virtual    HandleObject*    Last();
  72.  
  73. private:
  74.     const TList*    fList;
  75.     short            fIdx;
  76. };
  77.  
  78. inline HandleObject* TListIterator::Next()
  79. {
  80.     return fList->At(++fIdx);
  81. }
  82.  
  83. inline HandleObject* TListIterator::Prev()
  84. {
  85.     return fList->At(--fIdx);
  86. }
  87.  
  88. inline HandleObject* TListIterator::First()
  89. {
  90.     fIdx = 0;
  91.     return fList->At(fIdx);
  92. }
  93.  
  94. inline HandleObject* TListIterator::Last()
  95. {
  96.     fIdx = fList->Count() - 1;
  97.     return fList->At(fIdx);
  98. }
  99.  
  100. #endif
  101.